package com.b2b2c.until;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能概要：
 * 
 *
 */
public class PageResultListCovertMap<T> extends AbstractPageResult<T> implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Map<Integer, T> dataMap;//数据
	

	public Map<Integer, T> getdataMap() {
		
		return dataMap;
	}

	public void setDataMap(List<T> dataMap) {
		
		if (dataMap == null) {
			this.dataMap = new HashMap<Integer, T>();
			return ;
		}

    	Map<Integer, T> map = new HashMap<Integer, T>();
    	try {
	    	for (T t : dataMap) {
	    		map.put((Integer)(t.getClass().getMethod("getId").invoke(t)), t);
	    	}
    	} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		
		this.dataMap = map;
	}

	

	public static <T> PageResultListCovertMap<T> getResult(List<T> datas, AjaxPage pageObj) {
		
		PageResultListCovertMap<T> result = new PageResultListCovertMap<T>();
		
        result.setPageNo(pageObj.getNowPage());
        result.setPageSize(pageObj.getListRows());
        result.setDataMap(datas);
        result.setTotal(pageObj.getTotalRows());
        result.setPages(pageObj.getTotalPages());

        return result;
    }

	
}
